package me.bbvip.chat.entry;

import me.bbvip.chat.utils.DateUtils;

import java.util.Date;

/**
 * @author yonghui.cui
 * @version 1.0  2015/2/26
 */
public class MessageResponse {
    public final static int LEVEL_NORMAL = 0;
    public final static int LEVEL_INFO = 1;
    public final static int LEVEL_WARN = 2;
    public final static int LEVEL_ERROR = 3;

    public final static int MSG_OCDE_MSG = 1000; //普通消息
    public final static int MSG_OCDE_RESP_LOGIN = 2000; //登陆响应
    public final static int MSG_OCDE_RESP_MSG = 2001; //上行回复
    public final static int MSG_OCDE_SECRET_MSG = 2002; //私密消息
    public final static int MSG_OCDE_TIP_LOGIN = 2003; //登陆广播
    public final static int MSG_OCDE_SYS = 9000;   //系统消息


    private int level = LEVEL_NORMAL;//消息级别,0:普通消息,1：info消息,2:warn消息,3:error消息
    private int msgCode = MSG_OCDE_MSG;
    private String msg;//消息内容
    private String sourceId;
    private String sourceName;//消息来源
    private String directId;
    private String directName;
    private long time = new Date().getTime();

    public MessageResponse(String msg) {
        this.msg = msg;
    }

    public MessageResponse(int level, int msgCode, String msg) {
        this.level = level;
        this.msgCode = msgCode;
        this.msg = msg;
    }

    public MessageResponse(int level, int msgCode, String msg, String sourceName) {
        this.level = level;
        this.msgCode = msgCode;
        this.msg = msg;
        this.sourceName = sourceName;
    }

    public MessageResponse(int level, int msgCode, String msg, String sourceId, String sourceName) {
        this.level = level;
        this.msgCode = msgCode;
        this.msg = msg;
        this.sourceId = sourceId;
        this.sourceName = sourceName;
    }

    public MessageResponse(int level, int msgCode, String msg, String sourceId, String sourceName, String directId, String directName) {
        this.level = level;
        this.msgCode = msgCode;
        this.msg = msg;
        this.sourceId = sourceId;
        this.sourceName = sourceName;
        this.directId = directId;
        this.directName = directName;
    }

    public MessageResponse(String msg, String sourceId, String sourceName, String directId, String directName) {
        this.msg = msg;
        this.sourceId = sourceId;
        this.sourceName = sourceName;
        this.directId = directId;
        this.directName = directName;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public String getDirectId() {
        return directId;
    }

    public void setDirectId(String directId) {
        this.directId = directId;
    }

    public String getDirectName() {
        return directName;
    }

    public void setDirectName(String directName) {
        this.directName = directName;
    }

    public int getMsgCode() {
        return msgCode;
    }

    public void setMsgCode(int msgCode) {
        this.msgCode = msgCode;
    }

    public long getTime() {
        return time;
    }

    public String getTimeStr() {
        return DateUtils.date2String(new Date(this.time));
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("MessageResponse{");
        sb.append("level=").append(level);
        sb.append(", msg='").append(msg).append('\'');
        sb.append(", msgCode='").append(msgCode);
        sb.append(", sourceId='").append(sourceId).append('\'');
        sb.append(", sourceName='").append(sourceName).append('\'');
        sb.append(", directId='").append(directId).append('\'');
        sb.append(", directName='").append(directName).append('\'');
        sb.append(", time='").append(getTimeStr()).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
